<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			var str = prompt("请输入数值1，运算符，数值2，中间用逗号分隔：");
			var arr = str.split(",");
			var first = parseInt(arr[0]);
			// document.write(typeof(first));
			//var first = arr[0] - 0;//方式二：转换数值类型
			var flag = arr[1];
			var second = parseInt(arr[2]);
			//var second = arr[2] - 0;//
			// 大小转换
			if (first < second) {
				var temp = first;
				first = second;
				second = temp;
			}
			var result;
			switch (flag) {
				case "+":
					result = first + second;
					document.write(arr[0] + " " + arr[1] + " " + arr[2] + " = " + result);
					break;
				case "-":
					result = first - second;
					document.write(arr[0] + " " + arr[1] + " " + arr[2] + " = " + result);
					break;
				case "*":
					result = first * second;
					document.write(arr[0] + " " + arr[1] + " " + arr[2] + " = " + result);
					break;
				case "/":
					result = first / second;
					document.write(arr[0] + " " + arr[1] + " " + arr[2] + " = " + result);
					break;
				default:
					document.write("输入格式错误！");
			}
		</script>
	</head>
	<body>
	</body>
</html>
